<template>
  <div id="app">
    <i v-show="isShow">
      <router-view></router-view>
    </i>
  </div>
</template>

<script>
import { dingTalkPc } from "dingtalk-auth";
export default {
  name: "app",
  data: function() {
    return {
      isShow: false
    };
  },
  methods: {
    // 钉钉签名，免登调用
    authSerivce: function() {
      //JSAPILIST功能注册
      let ddjsApi = [
        "device.notification.alert",
        "device.notification.confirm",
        "runtime.permission.requestOperateAuthCode",
        "biz.util.uploadImage",
        "biz.contact.choose",
        "biz.util.share",
        "biz.ding.post",
        "biz.user.get"
      ];

      return new Promise(function(resolve, reject) {
        dingTalkPc.ddConfig(ddjsApi, "api/auth/getPcJsConfig").then(resCorpid => {
            localStorage.setItem("corpid", 'dingbbef8a86ef55e21735c2f4657eb6378f');
            console.log(resCorpid, "++++++++++resCorpid");
            dingTalkPc.authLogin("dingbbef8a86ef55e21735c2f4657eb6378f","api/auth/login" ).then(token => {
                //设置HTTP.Header值
                console.log(token)
                localStorage.setItem("token", token);
                sessionStorage.setItem("loginUser", JSON.stringify(token.user));
                resolve(token);
              });
          },err => {
            console.log("11111111");
          }
        );
      });
    }
  },

  created: function() {
    //钉钉软件内路由跳转
    //钉钉内首页路由跳转，签名，免登；
    this.authSerivce().then(res => {
      if(res.user.isAdmin == true || res.mongoRole == '1'){
        this.$message({
            message: '登陆成功',
            type: 'success'
        });
        this.isShow = true;
      } else{
        this.$message({
            message: '您没有该登陆权限',
            type: 'error'
        });
        this.isShow = false;
      }
      console.log("res----------===========-", res);
    });
  }
};
</script>

<style>

</style>
